package com.ailiwu.www.ailiwu.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;

/**
 * Author:    XiYoung
 * Version    V1.0
 * Date:      ${data}  ${time}
 * Description:
 * Modification  History:
 * Date         	Author        		Version        	Description
 * -----------------------------------------------------------------------------------
 * 2015/11/31       author              1.0                   1.0
 * Why & What is modified:
 */
public abstract class BaseFragment extends Fragment {
    protected Activity mAcAvtivity;
    protected static HttpUtils httpUtils;
    protected static Gson gson;
//    protected static DbUtils dbUtils;
//    protected static BitmapUtils bitmapUtils;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAcAvtivity = getActivity();
        httpUtils = new HttpUtils();
        //创建请求对象
        httpUtils = new HttpUtils();
        //设置连接超时时间
        httpUtils.configTimeout(30000);
        //设置缓存区中数据的存储时间，单位为毫秒（一旦超出指定时间，缓存内的数据会被清空）
        httpUtils.configDefaultHttpCacheExpiry(24 * 3600 * 1000);
        //设置缓存区的大小，单位是b字节
        httpUtils.configHttpCacheSize(4 * 1024 * 1024);
        gson = new Gson();
//        bitmapUtils = new BitmapUtils(mAcAvtivity);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflateView();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initData();
    }


    /**
     * 填充Fragment布局
     *
     * @return View；
     */
    protected abstract View inflateView();

    /**
     * 找控件
     */
    protected abstract void initView(View view);

    /**
     * 初始化数据
     */
    protected abstract void initData();

}
